from pydantic import BaseModel
from typing import Optional, Dict, Any
from datetime import datetime

class StreamBase(BaseModel):
    name: str
    url: str
    stream_type: Optional[str] = "rtsp"
    status: Optional[str] = "inactive"  # 默认状态改为inactive
    description: Optional[str] = ""
    inuse: Optional[int] = 1
    resolution: Optional[str] = None
    bitrate: Optional[int] = None
    fps: Optional[int] = None
    video_codec: Optional[str] = None
    audio_codec: Optional[str] = None
    act_uid: Optional[int] = None

class StreamCreate(StreamBase):
    pass

class StreamUpdate(BaseModel):
    name: Optional[str] = None
    url: Optional[str] = None
    stream_type: Optional[str] = None
    status: Optional[str] = None
    description: Optional[str] = None
    inuse: Optional[int] = None
    resolution: Optional[str] = None
    bitrate: Optional[int] = None
    fps: Optional[int] = None
    video_codec: Optional[str] = None
    audio_codec: Optional[str] = None

class StreamResponse(BaseModel):
    id: int
    name: str
    url: str
    stream_type: str
    status: str
    resolution: Optional[str] = None
    bitrate: Optional[int] = None
    fps: Optional[int] = None
    description: Optional[str] = ""
    is_recording: Optional[bool] = False
    is_pushing: Optional[bool] = False
    inuse: Optional[int] = 1
    video_codec: Optional[str] = None
    audio_codec: Optional[str] = None
    act_uid: Optional[int] = None
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    last_check: Optional[datetime] = None

    class Config:
        from_attributes = True